package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //查询所有
    @GetMapping("/category/findAll")
    public ResultInfo findAll(){
        //调用service
        List<Category> categoryList=categoryService.findAll();
        //返回结果
        return ResultInfo.success(categoryList);
    }
    //添加菜品
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){
        //调用service
        categoryService.save(category);
        //返回成功标识
        return ResultInfo.success(null);
    }
    //分类更新
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){
        //调用service
        categoryService.update(category);
        //返回成功标识
        return ResultInfo.success(null);
    }
    //分类删除
    @DeleteMapping("/category")
    public ResultInfo delete(Long id){
        //返回结果
        return categoryService.delete(id);
    }
    //根据type查询
    @GetMapping("/category/list")
    public ResultInfo findList(Integer type){
        //返回结果
        List<Category> list = categoryService.findList(type);
        return ResultInfo.success(list);
    }
}
